package com.shanhy.lixp.need001.service;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shanhy.lixp.need001.model.QichachaCompanyDetail;

/**
 * 单位Service
 *
 * @author 单红宇(365384722)
 * @myblog http://blog.csdn.net/catoop/
 */
@Service
public class QichachaHtmlService {

	private static final Logger logger = LoggerFactory.getLogger(QichachaHtmlService.class);

	@Autowired
	private QichachaHtmlParser qichachaHtmlParser;

	/**
	 * 获取网页数据
	 *
	 * @param name
	 *            企业名称
	 * @return
	 * @author SHANHY
	 */
	public QichachaCompanyDetail getQichachaCompanyDetail(String name) {
		logger.info("开始获取数据, name={}...", name);
		long startTime = System.currentTimeMillis();
		String str = qichachaHtmlParser.searchCompanyId(name);
		QichachaCompanyDetail detail = null;
		if(StringUtils.isNotBlank(str) && !str.equals("1") && !str.equals("2") && !str.equals("3")){
//			QichachaCompanyDetail detail = new QichachaCompanyDetail();
//			detail.setId(companyId);
//			detail.setName(name);
			
			detail = qichachaHtmlParser.getDetail(name, str);
		}else{
			detail = new QichachaCompanyDetail();
			detail.setErrorCode(str);
			logger.info("获取数据失败, errorCode={}, name={}...", detail.getErrorCode(), name);
		}
		logger.info("获取数据结束，耗时：{}ms", System.currentTimeMillis() - startTime);
		return detail;
	}

}
